#!/bin/bash

function pull(){
    image_az=$1
    image_harbor=$2
    docker pull ${image_az}
    docker tag ${image_az} ${image_harbor}
    docker push ${image_harbor}

}

if [[ -z "$1" ]]; then
  echo "image name is null"
  exit -1
fi
image_origin=$1
image_server=${image_origin%%/*}
image_body=${image_origin#*/}
image_body_k8s=${image_origin##*/}


if [[ "$image_server" == "k8s.gcr.io" ]]; then
  image_az="gcr.azk8s.cn/google_containers/$image_body_k8s"
  image_harbor="harbor.corp.hongen.com/google_containers/$image_body_k8s"
fi

if [[ "$image_server" == "quay.io" ]]; then
  image_az="quay.azk8s.cn/$image_body"
  image_harbor="harbor.corp.hongen.com/$image_body"
fi

echo "pull $image_az & tag to $image_harbor"
pull ${image_az} ${image_harbor}

